<?php

if(defined("_PARA_LINK_ROLL_LINK"))
    return;
define("_PARA_LINK_ROLL_LINK", 1);


class LinkRollLink extends HTMLable {
    public $id;
    public $url;
    public $headline;
    public $submitter;
    public $submitter_id;
    public $category_id;
    public $timestamp;
    public $approved;
    public $ip;

    public function LinkRollLink( $id,
                                  $url,
                                  $headline,
                                  $submitter,
                                  $submitter_id,
                                  $category_id,
                                  $timestamp,
                                  $approved,
                                  $ip
        ) {
        $this->id           = $id;
        $this->url          = $url;
        $this->headline     = $headline;
        $this->submitter    = $submitter;
        $this->submitter_id = $submitter_id;
        $this->category_id  = $category_id;
        $this->timestamp    = $timestamp;
        $this->approved     = $approved;
        $this->ip           = $ip;
    }

    // comparision function for sorting by id in descending order
    public static function cmp($a, $b) {
        if($a->id == $b->id)
            return 0;
        return ( $a->id < $b->id ) ? 1 : -1;   
    }

    public function htmlize( $options ) {

        if( $options['debug'] ) {
            echo "<pre>", var_dump( $this), "</pre>";
            return;
        }

        if($options['boxview'])
            return $this->htmlize_boxview();

        $safe_url = htmlspecialchars ( $this->url );
        if( $options['category'] )
            $catname = htmlspecialchars ( $options['category']->name );
        else
            $catname = "Ukendt";

        echo "<div class=\"para_linkroll_link\" id=\"para_linkroll_link_".$this->id . "\">";
        echo "<span class=\"para_linkroll_link_category\">" . $catname . "</span>";
        echo "<span class=\"para_linkroll_link_url\">";
        echo "<a target=\"_blank\" href=\"$safe_url\">". htmlspecialchars( $this->headline ) ."</a>";
        echo "</span>";
        echo "</div>\n";
    }


    private function htmlize_boxview() {
        echo "<div class=\"para_linkrollbox_link\" id=\"para_linkrollbox_link_".$this->id . "\">";
        echo "<a target=\"_blank\" href=\"$safe_url\" class=\"para_linkrollbox_linklink\">". htmlspecialchars( $this->headline ) ."</a>";        
        echo "</div>\n";
    }

}

?>
